#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int NUM = 50;
const int CAP = 1500;
int v[NUM];
int w[NUM];
int dp[NUM][CAP];
void knapsack(int c, int n)
{
	int jMax = min(w[n] - 1, c);
	for (int j = 0; j <= jMax; j++)
	{
		dp[n][j] = 0;
	}
	for (int j = w[n]; j <= c; j++)
	{
		dp[n][j] = v[n];
	}
	for (int i = n - 1; i > 0; i--)
	{
		jMax = min(w[i] - 1, c);
		for (int j = 0; j <= jMax; j++)
		{
			dp[i][j] = dp[i + 1][j];

		}
		for (int j = w[i]; j <= c; j++)
		{
			dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
		}
		
	}
}
int main()
{
	for (int i = 1; i <= 5; i++)
	{
		cin >> w[i];
	}
	for (int i = 1; i <= 5; i++)
	{
		cin >> v[i];
	}

	knapsack(10, 5);
	cout << dp[1][10] << endl;
	for (int i = 0; i <= 5; i++)
	{
		for (int j = 0; j <= 10; j++)
		{
			printf("%3d", dp[i][j]);
		}
		cout << endl;
	}
	return 0;
}